<?php
class Account_model extends Model{
    
    var $id = 0;
    var $username = "";
    var $password = "";
    var $fullname = "";
    var $birthday = "";
    var $address="";
    var $email="";
    var $phone="";
    var $sex =0;
    var $created_Date ="";
    var $account_Types_id=0; 
    
    function __construct(){
        parent::Model();
//        $this->load->helper('url');
    }
    
    function get_accounts()
    {
        $query = $this->db->get('accounts');
        return $query->result();
    }
    
    function validate() {
		$this->db->where('username', $this->input->post('username'));
		$this->db->where('password', md5($this->input->post('password')));
		$query = $this->db->get('users');
		if ($query->num_rows == 1) {
			return true;
		}
		else
		{
			return false;
		}
	}
    
    
    function createAccount(){
        $this->id = 0;
        $this->username = $this->input->post('username');
        $this->password = md5($this->input->post('password'));
        $this->fullname = $this->input->post('fullname');
        $this->birthday = $this->input->post('birthday');
        $this->address = $this->input->post('address');
        $this->email = $this->input->post('email');
        $this->phone = $this->input->post('phone');
        $this->sex = $this->input->post('sex');
        $this->account_Types_id = $this->input->post('accountType');
        $this->created_Date = time();
        
        $this->db->insert('accounts',$this);
    }
        
    function updateAccount(){
//        $this->id = 0;
        $this->id = $this->input->post('id');
        $this->username = $this->input->post('username');
        $this->password = md5($this->input->post('password'));
        $this->fullname = $this->input->post('fullname');
        $this->birthday = $this->input->post('birthday');
        $this->address = $this->input->post('address');
        $this->email = $this->input->post('email');
        $this->phone = $this->input->post('phone');
        $this->sex = $this->input->post('sex');
        $this->accountType = $this->input->post('accountType');
        $this->createdDate = time();
        
        $this->db->update('accounts', $this, array('id' => $_POST['id']));         
    }
    
    
} 

?>